import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    LoginUser: sessionStorage.getItem('LoginUser')
      ? JSON.parse(sessionStorage.getItem('LoginUser'))
      : null,
    Student: {
      studentid: 201727010308,
      collegename: '数学与信息学院',
      realname: '林先生'
    }, // 学生端用户对象
    submitedProvesNumber: -1,
    isCovering: false, // 设置幕布
    coverable: false,
    barCoverable: false,
    indexExamType: {
      typeName: '综合',
      num: 78
    },
    alwaysAddItems: [
      {
        index: 1,
        mark: 0.1
      },
      {
        index: 2,
        mark: 0.5
      },
      {
        index: 3,
        mark: 0.15
      },
      {
        index: 4,
        mark: 1.0
      },
      {
        index: 5,
        mark: 0.3
      },
      {
        index: 6,
        mark: 2.0
      }

    ],
    showReluWindow: false,
    showReluWindow2: false,
    selectedRelu: {
      subject: '德育',
      num: 0
    }, // 当前选中的条目，num从0开始
    relus: [
      {
        subject: '德育',
        items: []
      },
      {
        subject: '智育',
        items: []
      },
      {
        subject: '体育',
        items: []
      }
    ], // 条目
    yes: false, // 上一次弹窗操作是否点确认
    showEmpty: false, // 空空如也
    fileState: false, // file端是否为清除状态
    indexState1: false, // index端是否在管理状态（管理状态变为不通过）
    indexState2: false, // index端是否在批量处理状态
    action: true, // 一个不断改变的布尔值，用于监听某些异步过程
    action2: true, // 一个不断改变的布尔值，用于监听某些异步过程
    showDeletWindow: false, // 文件-显示删除弹窗
    addMark: null, // index请选择加分
    showIndexAddMarkWindow: false, // index加分弹窗是否展示
    channel: 1, // action通道
    showMakeSure: false, // 确认弹窗
    showMakeSure2: false,
    buff: null, // buff,
    showInfo: false, // 展示审核信息
    info: { // 信息
      url: '',
      title: '大学英语',
      content: '',
      appeal: '',
      name: '刘泳霖',
      number: '201727010310'
    },
    name: '数学与信息学院',
    Enumber: {
      nopassNum: 0,
      passedNum: 0,
      appeal: 0,
      stu: 0,
      college: 0,
      asso: 0,
      all: 0
    },
    headURL: 'http://47.103.124.147:80' // 后端服务器的域名
  },
  getters: {
    // Getter 接受 state 作为其第一个参数：
    getLoginUser: (state) => {
      return state.LoginUser
    },
    getSubmitedProvesNumber: (state) => {
      // 如果没有初始化过，进行初始化
      // if (state.submitedProvesNumber < 0) {
      //   // 调用异步action进行初始化
      //   // state.initSubmitedProvesNumber()
      //   state.submitedProvesNumber = 9
      // }
      return state.submitedProvesNumber
    }
  },
  // Mutation 必须是同步函数
  mutations: {
    // 更改 Vuex 的 store 中的状态的唯一方法是提交 mutation
    // state作为第一个参数
    // 还可以传入额外的参数，即 mutation 的 载荷（payload）
    // 在大多数情况下，载荷应该是一个对象，这样可以包含多个字段并且记录的 mutation 会更易读
    initUser (state, padyload) {
      state.LoginUser = padyload
    },
    setSubmitedProvesNumber (state, payload) {
      // alert('i am' + payload)
      state.submitedProvesNumber = payload
    },
    // 新提交证明以后，需要更新的数目，
    incrementSubmitedProvesNumber (state, payload) {
      state.submitedProvesNumber += payload
    },
    // 更改幕布状态
    changeCoverState (state, isCovering) {
      state.isCovering = isCovering
    },
    studentLogin (state, payload) {
      // state.Student.studentid = payload.studentid
      // state.Student.realname = payload.username
      // state.Student.collegename = payload.collegename
      const student = {
        studentid: payload.studentId,
        realname: payload.realName,
        collegename: payload.collegeName
      }
      state.Student = student
    },
    changeCoverableState (state, payload) {
      // 改变背景覆盖状态
      state.coverable = payload
    },
    changeBarCoverableState (state, payload) {
      // 改变bar背景覆盖状态
      state.barCoverable = payload
    },
    setAlwaysAddItems (state, paylod) {
      // 修改常用加分项
      state.alwaysAddItems = paylod
    },
    setIndexExamType (state, paylod) {
      // 修改学院端index下拉单属性
      state.indexExamType = paylod
    },
    setShowReluWindow (state, paylod) {
      // 修改是否展示条目选择弹窗
      state.showReluWindow = paylod
    },
    setShowReluWindow2 (state, paylod) {
      // 修改是否展示条目选择弹窗2
      state.showReluWindow2 = paylod
    },
    setSelectedRelu (state, paylod) {
      // 修改选中的relu
      state.selectedRelu = paylod
    },
    setRelus (state, paylod) {
      // 修改条目
      state.relus = paylod
    },
    setYes (state, paylod) {
      // 修改上一次弹窗选择状态
      state.yes = paylod
    },
    setShowEmpty (state, paylod) {
      // 修改是否展示空空如也
      state.showEmpty = paylod
    },
    setFileState (state, paylod) {
      // 修改file状态
      state.fileState = paylod
    },
    setIndexState1 (state, payload) {
      // 修改index的管理状态
      state.indexState1 = payload
    },
    setIndexState2 (state, payload) {
      // 修改index的批量处理状态
      state.indexState2 = payload
    },
    setAction (state, payload) {
      state.action = !state.action
      console.log(payload + '异步1')
    },
    setAction2 (state, payload) {
      state.action2 = !state.action2
      console.log(payload + '异步2')
    },
    setShowDeletWindow (state, payload) {
      state.showDeletWindow = payload
    },
    setAddMark (state, payload) {
      state.addMark = payload
    },
    setShowIndexAddMarkWindow (state, payload) {
      state.showIndexAddMarkWindow = payload
    },
    setChannel (state, payload) {
      state.channel = payload
    },
    setShowMakeSure (state, payload) {
      state.showMakeSure = payload
    },
    setShowMakeSure2 (state, payload) {
      state.showMakeSure2 = payload
    },
    setBuff (state, payload) {
      state.buff = payload
      console.log(state.buff)
    },
    setInfo (state, payload) {
      // 显示弹窗、更新弹窗的值
      state.info = payload
      state.showInfo = true
      state.coverable = true
      console.log(state.info)
    },
    setShowInfo (state, payload) {
      // state.info = payload
      state.showInfo = payload
    },
    setEnumber (state, payload) {
      // state.info = payload
      state.Enumber = payload
    }

  },
  // Action 类似于 mutation，不同在于：
  // Action 提交的是 mutation，而不是直接变更状态。
  // Action 可以包含任意异步操作。
  actions: {
  }
})
